package com.hroa.web.controller;

import com.hroa.common.util.bit.PropertiesConfigure;
import com.hroa.web.vo.ResponseEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 示例
 * @author is_zhoufeng
 *
 */
@Controller
@RequestMapping("/hello/")
public class HelloWorldControl {

	private static final Logger log = LoggerFactory.getLogger(HelloWorldControl.class);

	@Autowired
	private PropertiesConfigure propertiesConfigure;

	/**
	 * 普通http请求示例,浏览器输入http://127.0.0.1:8080/hello/index.htm进行访问
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("index.do")
	public String index(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		List<String> list = null;//userService.selectAll() ;
		modelMap.put("userList", "第一个以后");
		log.info("index request...");
		return "screen/user/index";
	}

	/**
	 * ajax请求示例（返回json内容）,浏览器输入http://127.0.0.1:8080/hello/test.json进行访问
	 * @param request
	 * @param response
	 */
	@RequestMapping("test.json")
	@ResponseBody
	public ResponseEntity<Void> json(HttpServletRequest request, HttpServletResponse response) {
		List<String> userList = null;//userService.selectAll();

		//		/*
		//		//业务成功，使用如下方式输出
		//		WebUtil.ajaxOutput(AjaxResult.newSuccessResult(userList), response);
		//		*/
		//
		//		//业务失败，使用如下方式输出
		//		WebUtil.ajaxOutput(AjaxResult.newFailResult(
		//				userList /*这个参数是返回的数据，随便传什么都行,可以为空*/,
		//				"请求出错啦", /*错误消息，自定义*/
		//				-1 /*这个参数是错误码，自定义*/ )
		//				, response);
		log.info("json request...");
		ResponseEntity<Void> responseEntity = new ResponseEntity<>();
		return responseEntity;
	}

	/**
	 * 去到上传文件页面,浏览器输入http://127.0.0.1:8080/hello/uploadView.htm进行访问
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("uploadView")
	public String uploadView(HttpServletRequest request, HttpServletResponse response) {
		return "hello/uploadView";
	}

	/**
	 * 上传文件示例
	 * @param file
	 * @param type
	 * @param request
	 */
	@RequestMapping("upload")
	public void uplaod(@RequestParam("file") MultipartFile file,
			@RequestParam(value = "type", required = false) String type, HttpServletRequest request,
			HttpServletResponse response) {

	}

	@RequestMapping("login")
	public String login(HttpServletRequest request, HttpServletResponse response) {
		return "hello/index";
	}

	@RequestMapping("mainIndex")
	public String mainIndex(HttpServletRequest request, HttpServletResponse response) {
		return "index/index";
	}

	@RequestMapping("holiday")
	public String holidayIndex(HttpServletRequest request, HttpServletResponse response) {
		return "index/holiday";
	}

	@RequestMapping("holidaySetting")
	public String holidaySetting(HttpServletRequest request, HttpServletResponse response) {
		return "index/holidaySetting";
	}

	@RequestMapping("pushTest.json")
	public void pushTest(Long userid ,HttpServletRequest request, HttpServletResponse response){

	}

}
